// <copyright file="EasyWebApp.cs" company="<Customer Name>">This is a "work-for-hire". or Copyright (C) 2010 MicroCODE Incorporated Troy, MI</copyright><author><Class Author's Name></author>

/*
 *      Title:    <Class Description>
 *      Module:   ClassTemplate (<Namespace>:ClassTemplate.cs)
 *      Project:  <Project Name>
 *      Customer: <Customer Name>
 *      Facility: MicroCODE Incorporated
 *      Date:     <Class Creation Date>
 *      Author:   <Class Author's Name>
 * 
 * 
 * 
 *  
 *      MODIFICATIONS:
 *      --------------
 *
 *  Date:         By-Group:   Rev:     Description:
 *
 *  DD-Mmm-YYYY   XYZ-GROUP  {0001}    Describe reason for creating or modifying class... 
 * 
 * 
 * 
 */

using System;
using System.Xml;
using Org.EasyWeb.Application;
using Org.EasyWeb.SysUtil;

namespace Org.EasyWeb.Sys
{
    internal class EasyWebConfigSection
    {
        // Fields
        private AppType fApplicationType;
        private string fConnectionString;
        private string fCultureName;
        private string fDBProvider;
        private bool fDebug;
        private int fIDStep;
        private bool fIsShowException;
        private int fMaxExcelRecords;
        private string fSolutionPath;
        private string fSqlProvider;
        private string fUploadPath;
        private string fUploadVirtualPath;
        private bool fUseCache;
        private bool fUseInternalXslt;

        // Methods
        public EasyWebConfigSection()
        {
        }

        public EasyWebConfigSection(XmlNode section)
        {
            this.ParseSection(section);
        }

        public IAppSettings GetAppSetting()
        {
            switch (this.fApplicationType)
            {
                case AppType.Web:
                    return new AppSettings(this);

                case AppType.Application:
                    return new AppToolkitAppSetting(this);
            }
            return null;
        }

        public void ParseSection(XmlNode section)
        {
            string value = XmlUtil.GetDefaultString(section, "application/@type", "Web");
            this.fApplicationType = (AppType)Enum.Parse(typeof(AppType), value);
            this.fSolutionPath = XmlUtil.GetDefaultString(section, "application/@path");
            this.fConnectionString = XmlUtil.GetDefaultString(section, "database/@connectionString");
            this.fDBProvider = XmlUtil.GetDefaultString(section, "database/@dbProvider", "SQL Server");
            this.fSqlProvider = XmlUtil.GetDefaultString(section, "database/@sqlProvider", "SQL Server");
            this.fIDStep = XmlUtil.GetDefaultInt(section, "database/@idStep", 1);
            this.fIsShowException = XmlUtil.GetDefaultBool(section, "debug/@isShowException", false);
            this.fUseCache = XmlUtil.GetDefaultBool(section, "debug/@useCache", true);
            this.fDebug = XmlUtil.GetDefaultBool(section, "debug/@debug", false);
            this.fUseInternalXslt = XmlUtil.GetDefaultBool(section, "other/@useInternalXslt", false);
            this.fCultureName = XmlUtil.GetDefaultString(section, "other/@culture", "zh-CN");
            this.fMaxExcelRecords = XmlUtil.GetDefaultInt(section, "other/@maxExcelRecords", 400);
            this.fUploadPath = XmlUtil.GetDefaultString(section, "upload/@path");
            this.fUploadVirtualPath = XmlUtil.GetDefaultString(section, "upload/@virtualPath", "../UploadFiles");
        }

        // Properties
        public AppType ApplicationType
        {
            get
            {
                return this.fApplicationType;
            }
        }

        public string ConnectionString
        {
            get
            {
                return this.fConnectionString;
            }
        }

        public string CultureName
        {
            get
            {
                return this.fCultureName;
            }
        }

        public string DBProvider
        {
            get
            {
                return this.fDBProvider;
            }
        }

        public bool Debug
        {
            get
            {
                return this.fDebug;
            }
        }

        public int IDStep
        {
            get
            {
                return this.fIDStep;
            }
        }

        public bool IsShowException
        {
            get
            {
                return this.fIsShowException;
            }
        }

        public int MaxExcelRecords
        {
            get
            {
                return this.fMaxExcelRecords;
            }
        }

        public string SolutionPath
        {
            get
            {
                return this.fSolutionPath;
            }
        }

        public string SqlProvider
        {
            get
            {
                return this.fSqlProvider;
            }
        }

        public string UploadPath
        {
            get
            {
                return this.fUploadPath;
            }
        }

        public string UploadVirtualPath
        {
            get
            {
                return this.fUploadVirtualPath;
            }
        }

        public bool UseCache
        {
            get
            {
                return this.fUseCache;
            }
        }

        public bool UseInternalXslt
        {
            get
            {
                return this.fUseInternalXslt;
            }
        }
    }
}